package com.example.tch.case04_16110100521;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

public class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private List<ArticleBean> list;
    private Context context;
    private LayoutInflater inflater;

    public MyAdapter(Context context){
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    public void setList(List<ArticleBean> list) {
        this.list = list;
    }



    @Override
    public int getItemCount() {
        return list.size();
    }



    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item,viewGroup,false);
        return new MyViewHolder(v);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
        ArticleBean article = list.get(i);
        if (article == null) return;
        MyViewHolder viewholder = (MyViewHolder) viewHolder;
        viewholder.title.setText(article.getTitle());

    }
    class MyViewHolder extends RecyclerView.ViewHolder {
        TextView title;
        public MyViewHolder(View itemView)
        { super(itemView);
            title = itemView.findViewById(R.id.textView );
        }
    }
}

